<html>
<head><meta charset="utf-8"><title>enum varient designator in macro_rules! · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/enum.20varient.20designator.20in.20macro_rules!.html">enum varient designator in macro_rules!</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233212864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/enum%20varient%20designator%20in%20macro_rules%21/near/233212864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/enum.20varient.20designator.20in.20macro_rules!.html#233212864">(Apr 05 2021 at 18:49)</a>:</h4>
<p>Maybe this has been discussed as part of Macros V2, or just that proc macros can cover it, but it would be really handy to have a designator which works for enum variants, rather than the enum type itself. It seems like something which would not be unreasonable to add to <code>macro_rules!</code>? Something like <code>:variant</code>?</p>



<a name="233215481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/enum%20varient%20designator%20in%20macro_rules%21/near/233215481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/enum.20varient.20designator.20in.20macro_rules!.html#233215481">(Apr 05 2021 at 19:09)</a>:</h4>
<p>Macros know nothing about types, so for example in case of <code>Foo::Bar</code> it is undetermined if this is the <code>Bar</code> variant of <code>Foo</code> or the <code>Bar</code> type in the module <code>Foo</code>.</p>



<a name="233221272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/enum%20varient%20designator%20in%20macro_rules%21/near/233221272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/enum.20varient.20designator.20in.20macro_rules!.html#233221272">(Apr 05 2021 at 19:57)</a>:</h4>
<p>Variants themselves are <code>ident</code>ifiers when within an <code>enum</code> definition, <code>path</code>s otherwise. Did neither of these captures suffice?</p>



<a name="233222861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/enum%20varient%20designator%20in%20macro_rules%21/near/233222861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/enum.20varient.20designator.20in.20macro_rules!.html#233222861">(Apr 05 2021 at 20:10)</a>:</h4>
<p>Hmm, I'll have to try <code>ident</code> and/or <code>path</code>. The available docs on this make it very hard to figure out what to use for some pretty common cases, e.g. <a href="https://doc.rust-lang.org/reference/macros-by-example.html#metavariables">https://doc.rust-lang.org/reference/macros-by-example.html#metavariables</a> won't really get you far on answering this question, unfortunately.</p>



<a name="233223277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/enum%20varient%20designator%20in%20macro_rules%21/near/233223277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/enum.20varient.20designator.20in.20macro_rules!.html#233223277">(Apr 05 2021 at 20:15)</a>:</h4>
<p>Yeah, there is room for improving the teaching materials for macros <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="233232484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/enum%20varient%20designator%20in%20macro_rules%21/near/233232484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/enum.20varient.20designator.20in.20macro_rules!.html#233232484">(Apr 05 2021 at 21:17)</a>:</h4>
<p>Neither <code>:ident</code> or <code>:path</code> seem to work. I'm trying to macro out a bunch of similar <code>match</code> sub-statements, for what it's worth. And I was trying with <code>Enum::Varient</code> in full.</p>



<a name="233236695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/enum%20varient%20designator%20in%20macro_rules%21/near/233236695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/enum.20varient.20designator.20in.20macro_rules!.html#233236695">(Apr 05 2021 at 21:54)</a>:</h4>
<p><code>Enum::Variant</code> should match <code>:path</code> and <code>:ty</code>, but won't match <code>:ident</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>